#*-- coding:utf-8 --*
import xml.dom.minidom as minidom
from xml.dom.minidom import Node
from  base64 import *

doc = minidom.parse("ansfile_k.xml")

print 'reading'

for node in doc.getElementsByTagName("ansfile_k"):
    ans_type = node.getElementsByTagName("ans_type")[0].childNodes[0].data
    ans_id = node.getElementsByTagName("ans_id")[0].childNodes[0].data
    ans_text = b64decode(node.getElementsByTagName("ans_file")[0].childNodes[0].data)
    print 'writing %s_%s.xls' % (ans_type, ans_id)
    f = open('%s_%s.xls' % (ans_type, ans_id), 'wb')
    f.write(ans_text)
    f.close()
    print 'finished'
print 'press anykey'
raw_input()
    
    
    
    
    
    
    

